package eu.telecom_bretagne.RECRUT.demo;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import eu.telecom_bretagne.RECRUT.data.model.Archive;
import eu.telecom_bretagne.RECRUT.service.IServiceArchive;

public class AppelServiceArchive {

	public static void main(String[] args) {

		test_listeArchives();

		test_modifierArchive();
		test_lireArchive();
		
		test_creerArchive();
		test_listeArchives();
				
		test_supprimerAchive(1);
		test_listeArchives();
				
	}

	public static IServiceArchive getServiceArchive() {

		InitialContext ctx;
		IServiceArchive serviceArchive = null;
		try {

			ctx = new InitialContext();
			serviceArchive = (IServiceArchive) ctx
					.lookup(IServiceArchive.JNDI_NAME);
		} catch (NamingException e) {

			// Unable to retrieve the context or the service
			e.printStackTrace();
			System.exit(-1);
		}
		return serviceArchive;
	}

	public static void test_listeArchives() {

		for (Archive archive : getServiceArchive().listeArchives()) {
			System.out.println("Archive id:" + archive.getId() + " titre:"
					+ archive.getTitre());
		}
	}

	public static void test_lireArchive() {

		Archive archive = getServiceArchive().lireArchive(1);
		System.out.println("Archive id=1 titre:" + archive.getTitre());
	}

	public static void test_modifierArchive() {

		getServiceArchive().modifierArchive(1, "Archive Compta");
	}
	
	public static void test_creerArchive (){
		
		getServiceArchive().creerArchive("Nouvelle archive du dossier 1", 1, 1);
	}
	
	public static void test_supprimerAchive (int id){
		
		getServiceArchive().supprimerArchive(id);
	}
	

}
